package com.su.util;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class SendMsgUtil {
	/**
	 * 发送短信消息
	  * 方法说明
	  * @Discription:扩展说明
	  * @param phones
	  * @param content
	 * @throws IOException 
	 * @throws UnsupportedEncodingException 
	 */
	public static String sendMsg(String phones,String content) throws HttpException, IOException{
 		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://utf8.api.smschinese.cn"); 
		post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
		NameValuePair[] data ={ new NameValuePair("Uid", "ssaiwey"),new NameValuePair("Key", "6b708a53c5852d83c759"),new NameValuePair("smsMob",phones),new NameValuePair("smsText","你的密码为:"+content+"【蚌埠医学院第一附属医院】")};
		post.setRequestBody(data);

		client.executeMethod(post);
		Header[] headers = post.getResponseHeaders();
		int statusCode = post.getStatusCode();
		System.out.println("statusCode:"+statusCode);
		for(Header h : headers)
		{
		System.out.println(h.toString());
		}
		String result = new String(post.getResponseBodyAsString().getBytes("gbk")); 
		System.out.println(result);
		post.releaseConnection();
		return result;
	}
	
	/**
	 * 随机生成6位随机验证码
	  * 方法说明
	  * @Discription:扩展说明
	  * @return
	  * @return String
	  * @Author: feizi
	  * @Date: 2015年4月17日 下午7:19:02
	  * @ModifyUser：feizi
	  * @ModifyDate: 2015年4月17日 下午7:19:02
	 */
	public static String createRandomVcode(){
		//验证码
		String vcode = "";
		for (int i = 0; i < 6; i++) {
			vcode = vcode + (int)(Math.random() * 9);
		}
		return vcode;
	}
	
	/**
	 * 测试
	  * 方法说明
	  * @Discription:扩展说明
	  * @param args
	  * @return void
	 * @throws IOException 
	 * @throws HttpException 
	  * @Author: feizi
	  * @Date: 2015年4月17日 下午7:26:36
	  * @ModifyUser：feizi
	  * @ModifyDate: 2015年4月17日 下午7:26:36
	 */
/*	public static void main(String[] args) throws HttpException, IOException {
 		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://utf8.api.smschinese.cn"); 
		post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
		NameValuePair[] data ={ new NameValuePair("Uid", "ssaiwey"),new NameValuePair("Key", "6b708a53c5852d83c759"),new NameValuePair("smsMob","18225903276"),new NameValuePair("smsText","你好你的密码为:520【卫宁健康科技集团股份有限公司】")};
		post.setRequestBody(data);
        //http://www.smschinese.cn/reg.shtml
		client.executeMethod(post);
		Header[] headers = post.getResponseHeaders();
		int statusCode = post.getStatusCode();
		System.out.println("statusCode:"+statusCode);
		for(Header h : headers)
		{
		System.out.println(h.toString());
		}
		String result = new String(post.getResponseBodyAsString().getBytes("gbk")); 
		System.out.println(result);
		post.releaseConnection();
	}*/
}
